package com.lyy.photovoltaic.controller;

import com.alibaba.fastjson.JSONObject;
import com.lyy.photovoltaic.beans.UserCartDetails;
import com.lyy.photovoltaic.common.vo.ResultVO;
import com.lyy.photovoltaic.service.UserCartDeatilsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/userCartDetails")
@Api(value = "用户购物车详情接口", tags = "购物车详情管理")
public class UserCartDetailsController {
    @Autowired
    UserCartDeatilsService userCartDeatilsService;
    @PostMapping(value = "/addEquipment")
//    @ApiImplicitParam(dataType = "string", name = "uCId", value = "根据用户购物车uCId查询相关购物车详情", required = true)
    public ResultVO addUserCartDetails(@RequestBody UserCartDetails userCartDetails) {
        ResultVO resultVO = userCartDeatilsService.addUserCartDetails(userCartDetails);
        return resultVO;
    }
    @GetMapping(value = "/{uCId}")
    @ApiImplicitParam(dataType = "string", name = "uCId", value = "根据用户购物车uCId查询相关购物车详情", required = true)
    public ResultVO getUserCartDetailsByUCID(@PathVariable("uCId") String uCId) {
        ResultVO resultVO = userCartDeatilsService.getUserCartDetailsByUCID(uCId);
        return resultVO;
    }

    @PostMapping(value = "/count")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "num", value = "根据用户购物车详情id更新相关设备数量", required = true),
            @ApiImplicitParam(dataType = "string", name = "uCDId", value = "根据用户购物车详情id", required = true)
    })
    public ResultVO updateUserCartDetailsCount(@RequestParam("num") int num,@RequestParam("uCDId")String uCDId) {
        ResultVO resultVO = userCartDeatilsService.updateUserCartDetailsCount(uCDId,num);
        return resultVO;
    }
    @DeleteMapping(value = "/{uCDId}")
    @ApiImplicitParam(dataType = "string", name = "uCDId", value = "根据用户购物车uCDId删除购物车中的商品", required = true)
    public ResultVO deleteUserCartDetails(@PathVariable("uCDId") String uCDId) {
        ResultVO resultVO = userCartDeatilsService.deleteUserCartDetails(uCDId);
        return resultVO;
    }
    @DeleteMapping(value = "/deleteUserCartDetails")
//    @ApiImplicitParam(dataType = "string", name = "uCDId", value = "根据用户购物车uCDId删除购物车中的商品", required = true)
    public ResultVO batchDeleteUserCartDetails(@RequestBody String[] eIds) {
        ResultVO resultVO = userCartDeatilsService.batchDeleteUserCartDetails(eIds);
        return resultVO;
    }
    @PostMapping(value = "/batchAdd")
//    @ApiImplicitParam(dataType = "string", name = "uCId", value = "根据用户购物车uCId查询相关购物车详情", required = true)
    public ResultVO batchAddUserCartDetails(@RequestBody JSONObject jsonObject) {
        ResultVO resultVO = userCartDeatilsService.batchAddUserCartDetails(jsonObject);
        return resultVO;
    }
}
